import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

// 导入路由集合
import { baseRouters } from "./base"; // 基础路由
import { systemRouters } from "./system"; // 管理系统

// 配置路由
const routerConfig = {
  mode: "history",
  routes: [...baseRouters, ...systemRouters]
};
const router = new Router(routerConfig);

//跳转路由之前验证
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    let userInfo = sessionStorage.getItem("user"); //获取当前登录状态
    if (userInfo) {
      next(); // 如果已登录则正常跳转
    } else {
      next({
        path: "/"
      });
    }
  } else {
    next();
  } // 登陆状态判定和权限【权限还没做】
});

//路由调用之后
router.afterEach(() => {});

export default router;
